package cn.tedu.sgs.garbage.service.impl;

import cn.tedu.sgs.garbage.mapper.GarbageMapper;
import cn.tedu.sgs.garbage.pojo.dto.GarbageQuery;
import cn.tedu.sgs.garbage.pojo.dto.GarbageSaveParam;
import cn.tedu.sgs.garbage.pojo.entity.Garbage;
import cn.tedu.sgs.garbage.pojo.vo.GarbageVO;
import cn.tedu.sgs.garbage.service.GarbageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class GarbageServiceImpl implements GarbageService {
	@Autowired
	GarbageMapper garbageMapper;
	@Override
	public List<GarbageVO> selectGarbage(GarbageQuery garbageQuery) {
		log.debug("查询垃圾业务，参数：{}", garbageQuery);
		List<GarbageVO> list = garbageMapper.selectGarbage(garbageQuery);
		return list;
	}

	@Override
	public void saveGarbage(GarbageSaveParam garbageSaveParam) {
		log.debug("保存垃圾参数:{}",garbageSaveParam);
		Garbage garbage = new Garbage();
		BeanUtils.copyProperties(garbageSaveParam,garbage);
		if(garbage.getId()==null){
			garbageMapper.insert(garbage);
		}else{
			garbageMapper.update(garbage);
		}
	}

	@Override
	public void deleteGarbage(Long id) {
		log.debug("删除垃圾参数:{}",id);
		garbageMapper.deleteById(id);
	}
}
